<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="html" uri="http://www.springframework.org/tags/form" %>
<c:set value="${ctx}" var = "ctx"/>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>MMLOO</title>
  <link rel="stylesheet" href="${ctx}/resources/plugins/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="${ctx}/resources/css/webuploader.css">
  <link rel="stylesheet" href="${ctx}/resources/plugins/image_css/global.css">
  <link rel="stylesheet" href="${ctx}/resources/css/global.css">

  <!--[if lt IE 9]>
  <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body>
<jsp:include page="../../../home/navigator.jsp"></jsp:include>

<div class="container" style="width:1200px;height:600px;color:#66afe9">

  <div class="main-content" >
    <form name="fastBuy" id="fastBuy" class="form-horizontal"  action="${ctx}/manage/goods/promotion/fastBuy/add" method="post">
      <div align="left" style="width: 600px; margin-right: auto; margin-left: auto;">
        <div class="form-group">
          <label for="number" class="col-sm-2 control-label"><span style="color:red;">*</span>抢购编号</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="number" name="number" value="${fastBuy.number}" readonly/>
          </div>
        </div>

        <div class="form-group">
          <label  class="col-sm-2 control-label"><span style="color:red;">*</span>允许抢购的商品</label>
          <div class="col-sm-10">

            <input type="text" class="form-control hidden" name="goods_ids" id="goods_ids" value="${fastBuy.goods_ids}"
                   required>
            <button onclick="selectGoods('<c:url value="${ctx}/manage/goods/list/json"/>')"
                    class="btn btn-primary btn-xs"
                    data-toggle="modal" data-target="#selectGoods">选择
            </button>
          </div>
        </div>
        <div class="form-group">
          <label  class="col-sm-2 control-label"><span style="color:red;">*</span>秒杀价</label>
          <div class="col-sm-10">
            <input type="range" class="form-control" name="fast_price" id="fast_price" value="${fastBuy.fast_price}"
                   required>
          </div>
        </div>
        <div class="form-group">
          <label  class="col-sm-2 control-label"><span style="color:red;">*</span>秒杀时长</label>
          <div class="col-sm-10">
            <input type="number" class="form-control" name="fast_time" id="fast_time" value="${fastBuy.fast_time}"
                   required>
          </div>
        </div>
        <div class="form-group">
          <%--<div class="col-lg-6 col-md-6 col-sm-6">--%>

          <%--</div>--%>

          <label  class="col-sm-2 control-label"><span style="color:red;">*</span>开始时间</label>
          <div class="col-sm-10">
            <input type="date" class="form-control input-editable" name="start_time" id="start_time" value="${fastBuy.start_time}" required>
          </div>
        </div>
        <div class="form-group">
          <label  class="col-sm-2 control-label"><span style="color:red;">*</span>结束时间</label>
          <div class="col-sm-10">
            <input type="date" class="form-control input-editable" name="end_time" id="end_time" value="${fastBuy.end_time}" required>
          </div>
        </div>
        <input type="hidden" name="id" value="${fastBuy.id}"/>
        <div class="form-group">
          <div class="col-sm-offset-2 col-sm-10">
            <input type="submit" value="提交" class="btn btn-primary" id="save-img" onclick="return form_handle();"/> <input type="reset" value="重置"
                                                                                                                           class="btn btn-default" />
          </div>
        </div>

      </div>

    </form>

  </div>
</div>
</div>
<script src="${ctx}/resources/plugins/jquery-2.0.3.min.js"></script>
<script src="${ctx}/resources/plugins/bootstrap/js/bootstrap.js"></script>
<script src="${ctx}/resources/js/webuploader/webuploader.min.js"></script>
<script src="${ctx}/resources/js/jquery.masonry.min.js"></script>
<script src="${ctx}/resources/js/global.js"></script>
<script src="${ctx}/resources/plugins/image_global/global.js"></script>
<script src="${ctx}/resources/js/manage.js"></script>

<script type="application/javascript">

  function form_handle(){
    if ($("#goods_ids").val() !== undefined && $("#goods_ids").val() !== "")
      $("#fastBuy").submit();
    return false;
  }
  function selectGoods(path) {
    $.ajax({
      url: path,
      type: 'get',
      async: true,
      dataType: 'json',
      success: function (data) {
        alert(data);
        $("#pageNo").val(data.data.pageNo);
        $("#pageSize").val(data.data.pageSize);
        $("#pager_end").empty();
        $("#tbody").empty();
        $("#select_with_saleType").empty();
        var a_1 = '<button class="btn btn-primary btn-xs" data-toggle="modal" data-target="#selectGoods" onclick="selectGoods(\'/manage/goods/list/json?pageNo='+ data.data.pageNo + '&pageSize='+ data.data.pageSize + '&sale_type=1\')' + '">最新</button>';
        var a_2 = '<button class="btn btn-primary btn-xs" data-toggle="modal" data-target="#selectGoods" onclick="selectGoods(\'/manage/goods/list/json?pageNo='+ data.data.pageNo + '&pageSize='+ data.data.pageSize + '&sale_type=2\')' + '">特卖</button>';
        var a_3 = '<button class="btn btn-primary btn-xs" data-toggle="modal" data-target="#selectGoods" onclick="selectGoods(\'/manage/goods/list/json?pageNo='+ data.data.pageNo + '&pageSize='+ data.data.pageSize + '&sale_type=3\')' + '">热卖</button>';
        var a_4 = '<button class="btn btn-primary btn-xs" data-toggle="modal" data-target="#selectGoods" onclick="selectGoods(\'/manage/goods/list/json?pageNo='+ data.data.pageNo + '&pageSize='+ data.data.pageSize + '&sale_type=4\')' + '">推荐</button>';
        $("#select_with_saleType").append(a_1).append(a_2).append(a_3).append(a_4);
        $.each(data.data.list, function (idx, obj) {
          var tr_begin = '<tr class="success">';
          var tr_end = '</tr>';
          var td_1 = '<td><input type="checkbox" name="select_checkbox" id="'+obj.id+'" onclick="selected('+obj.id+')" value="' + obj.number + '"/></td>';/* name="select" value="' + obj.id + '*/
          var td_2 = '<td>' + obj.number + '</td>';
          var td_3 = '<td>' + obj.name + '</td>';
          var td_4 = '<td>' + obj.brief + '</td>';
          var td_5 = '<td>' + obj.showtime + '</td>';
          var td_6 = '<td>最新</td>';
          if(obj.sale_type == 2){
            td_6 = '<td>特卖</td>';
          }else if(obj.sale_type == 3){
            td_6 = '<td>热卖</td>';
          }else if(obj.sale_type == 4){
            td_6 = '<td>推荐</td>';
          }
          $("#tbody").append(tr_begin).append(td_1).append(td_2)
                  .append(td_3).append(td_4).append(td_5).append(td_6).append(tr_end);



        });
        alert("2 - >"+data.data.pager_end);
        var pager_end = '<div>' + data.data.pager_end + '</div>';
        $("#pager_end").append(pager_end);
      }
    });
  }
  /*'+this+'*/
  var select_val = "";
  function selected(s){
    alert("val - " + $("input[name='select_checkbox']").prop("checked"));
    select_val = select_val + s;

  }
  var submitFlag = true;
  function selectButton(){
    var check_val = [];
    alert("select_val = " + select_val);
    var obj = document.getElementsByName("select_checkbox");
    for(k in obj){
      if(obj[k].checked)
        check_val.push(obj[k].value);
    }

    if (!$("input[name='select_checkbox']").prop("checked")) {
      alert("还没选择哟！");
      return false;
    } else {
      submitFlag = true;
    }
    if(submitFlag){
      $.ajax({
        url: '/manage/goods/promotion/add/json?select='+check_val,
        type: 'post',
        async: true,
        dataType: 'json',
        success: function (data) {
          alert("select -- " + data.data);
          $("#goods_ids").removeClass("hidden");
          $("#goods_ids").val(data.data);
          document.getElementById("close").click();
        }
      });
    }

  }
</script>
<div class="modal fade" id="selectGoods" tabindex="-1" role="dialog">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" id="close" data-dismiss="modal">
          <span aria-hidden="true">&times;</span>
          <span class="sr-only">Close</span>
        </button>
        <h3 class="modal-title">选择商品</h3>
      </div>
      <div class="modal-body"  style="color:#66afe9">

        <%--<div class="col-sm-6 pull-right">
          <form id="searchForm" method="post" action="${ctx}/manage/goods/list/json">
            <div class="input-group">
              <input id="pageNo" name="pageNo" type="hidden" value=""/>
              <input id="pageSize" name="pageSize" type="hidden" value=""/>
              <span class="input-group-addon">商品：</span>
              <input type="text" class="form-control" name="keyword" value="${keyword}"
                     placeholder="请输入你要查询的商品" required>
                      <span class="input-group-btn">
                        <button class="btn btn-default" type="submit" onclick="return page();">查询</button>
                      </span>
            </div>
          </form>
        </div>--%>
        <div id="select_with_saleType" style="margin-bottom: 3px;" class="btn-group">

        </div>
        <table class="table">
          <thead>
          <tr>
            <th>选择</th>
            <th>编号</th>
            <th>名称</th>
            <th>简介</th>
            <th>上架时间</th>
            <th>售卖类型</th>
          </tr>
          </thead>
          <tbody id="tbody"  class="table">
          </tbody>
        </table>
        <input type="submit" value="确定" class="btn btn-primary" onclick="selectButton()"/>
        <div id="pager_end"  class="col-sm-6 pull-right">

        </div>
      </div>
    </div>
  </div>
</div>

</body>
</html>
